package fly.gdx.graphics;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.Viewport;

import fly.shared.Event;

public class FlyScene2D extends Stage
{
	private FlyRenderer2D renderer = null;
	
	private Event<FlyRenderer2D> render_event_a = null;
	private RenderEvent render_event_b = null;
	
	
	public FlyScene2D(){this(false);}
	public FlyScene2D(boolean font_use_chinese)
	{
		super();
		this.Init();
		
		if(font_use_chinese)
			renderer = new FlyRenderer2D(font_use_chinese);
		else
			renderer = new FlyRenderer2D();
	}
	
	
	public FlyScene2D(Viewport viewport){this(viewport,false);}
	public FlyScene2D(Viewport viewport,boolean font_use_chinese)
	{
		super(viewport);
		this.Init();
		
		if(font_use_chinese)
			renderer = new FlyRenderer2D(font_use_chinese);
		else
			renderer = new FlyRenderer2D();
	}

	
	private void Init()
	{
		render_event_a = new Event<FlyRenderer2D>() {
			@Override public void invoke(FlyRenderer2D t) {	}
		};
		
		render_event_b = new RenderEvent() {
			@Override public void RenderShape(FlyRenderer2D renderer) {}
			@Override public void RenderImage(FlyRenderer2D renderer) {}
			@Override public void RenderText(FlyRenderer2D renderer) {}
		};
	}
	
	
	@Override
	public void dispose()
	{
		super.dispose();
		this.renderer.Dispose();
	}
	
	
	
	@Override
	public void draw()
	{
		super.draw();
		
		this.renderer.GetRenderer().setProjectionMatrix(super.getCamera().combined);
		this.renderer.GetBatch().setProjectionMatrix(super.getCamera().combined);
		
		this.renderer.Begin(ShapeRenderer.ShapeType.Line);
		this.render_event_a.invoke(this.renderer);
		this.renderer.End();
		
		this.renderer.ShapeRendererBegin(ShapeRenderer.ShapeType.Line);
		this.render_event_b.RenderShape(this.renderer);
		this.renderer.ShapeRendererEnd();
		
		this.renderer.BatchBegin();
		this.render_event_b.RenderText(this.renderer);
		this.render_event_b.RenderImage(this.renderer);
		this.renderer.BatchEnd();
	}
	
	
	public FlyRenderer2D GetRenderer(){return this.renderer;}

	
	public float GetWidth() {return super.getWidth();}
	public float GetHeight() {return super.getHeight();}
	
	
	public void SetRenderEvent(Event<FlyRenderer2D> render_event)
	{
		this.render_event_a = render_event;
	}
	
	public void SetRenderEvent(RenderEvent render_event)
	{
		this.render_event_b = render_event;
	}
}





















